﻿using IDAdmin.Common;
using IDAdmin.Lib.DataLayer;
using IDAdmin.Lib.UI;
using IDAdmin.Lib.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IDAdmin.Pages
{
    public partial class ExchangeUsingServer : BasePage
    {
        public ExchangeUsingServer()
            : base(Lib.AppFunctions.EXCHANGEUSINGSERVER)
        {

        }
        protected override void Page_Load(object sender, EventArgs e)
        {
            if (!IsLogin())
            {
                RedirectToLogOn();
            }
            else if (!CheckRight())
            {
                RedirectToDeniedMessage();
            }
        }

        protected void countButton_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = new DateTime();
            DateTime dtToDate = new DateTime();
            if (!string.IsNullOrEmpty(countToolBar.beginDateTextBox.Text))
            {
                dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.beginDateTextBox.Text);
            }
            if (!string.IsNullOrEmpty(countToolBar.beginDateTextBox.Text))
            {
                dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.toDateTextBox.Text);
            }
            List<DateTime> dateTimeList = new List<DateTime>();
            if (!string.IsNullOrEmpty(Convert.ToString(dtFormDate)) && !string.IsNullOrEmpty(Convert.ToString(dtToDate)))
            {
                dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            }
            dataPanel.Controls.Add(getStatsConsume(dateTimeList));
        }

        private Table getStatsConsume(List<DateTime> dateTimeList)
        {
            Table table = new Table();
            table.CssClass = "table1";
            TableRow rowHeader = new TableRow();
            TableRow rowTitle = new TableRow();
            rowTitle.Cells.AddRange
            (
                new TableCell[]
                {
                    UIHelpers.CreateTableCell("Tổng cộng các Server", HorizontalAlign.Center,"cell1",7),
                }
            );
            rowHeader.Cells.AddRange(
                new TableCell[]
                { 
                    UIHelpers.CreateTableCell("Ngày",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng đổi",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu đổi Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu hao trong IB Shop",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tiêu hao thị trường đấu giá Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tiêu hao khác",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                }
            );
            table.Rows.Add(rowHeader);
            Dictionary<string, List<StatsComsume>> listComsume = WebDB_N.GetStatsConsume(dateTimeList);         
            try
            {
                string css;
                int stt = 0;
                for (int i = 0; i < listComsume.Count;i++)
                {
                    rowTitle.Cells.AddRange
                    (
                        new TableCell[]
                        {
                            UIHelpers.CreateTableCell(listComsume.ElementAt(i).Key,Unit.Percentage(5), HorizontalAlign.Center,"cell1",7),
                        }
                    );
                    if ((i + 1) == listComsume.Count())
                    {
                        table.Rows.Add(rowTitle);
                    }

                    rowHeader.Cells.AddRange(
                       new TableCell[]
                        { 
                            UIHelpers.CreateTableCell("Ngày",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng đổi",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu đổi Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu hao trong IB Shop",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tiêu hao thị trường đấu giá Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tiêu hao khác",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                        }
                   );
                    if ((i + 1) == listComsume.Count())
                    {
                        table.Rows.Add(rowHeader);
                    }
                    stt++;
                }
                //content

                int index = 0;

                foreach (var record in listComsume.ElementAt(listComsume.Count - 1).Value)
                {

                    int totalGoldChangePoint = 0;
                    int totalGoldSpend = 0;
                    int totalGoldSpendSilver = 0;
                    int totalGoldChangeSilver = 0;
                    int totalGoldIBShop = 0;

                    index++;
                    css = index % 2 == 0 ? "cell1" : "cell2";
                    TableRow row = new TableRow();

                    int j = 0;
                    while (j < listComsume.Count)
                    {
                        totalGoldChangePoint += listComsume.ElementAt(j).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(j).Value.ElementAt(index - 1).totalgoldchange) : 0;
                        totalGoldSpend += listComsume.ElementAt(j).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(j).Value.ElementAt(index - 1).totalgoldspend) : 0;
                        totalGoldSpendSilver += listComsume.ElementAt(j).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(j).Value.ElementAt(index - 1).totalgoldspendsilver) : 0;
                        totalGoldChangeSilver += listComsume.ElementAt(j).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(j).Value.ElementAt(index - 1).totalgoldchangesilver) : 0;
                        totalGoldIBShop += listComsume.ElementAt(j).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(j).Value.ElementAt(index - 1).totalgoldibshop) : 0;
                        j++;
                    }

                    row.Cells.AddRange
                    (
                        new TableCell[]
                               {
                                    UIHelpers.CreateTableCell(record.datetime.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldChangePoint).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldSpend).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),    
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldChangeSilver).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldIBShop).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldSpendSilver).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell("0",HorizontalAlign.Center,css)
                               }
                    );

                    int z = 0;
                    while (z < listComsume.Count)
                    {
                        row.Cells.AddRange
                       (
                           new TableCell[]
                               {
                                    UIHelpers.CreateTableCell(record.datetime.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(listComsume.ElementAt(z).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(z).Value.ElementAt(index - 1).totalgoldchange).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(listComsume.ElementAt(z).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(z).Value.ElementAt(index - 1).totalgoldspend).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),    
                                    UIHelpers.CreateTableCell(listComsume.ElementAt(z).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(z).Value.ElementAt(index - 1).totalgoldchangesilver).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(listComsume.ElementAt(z).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(z).Value.ElementAt(index - 1).totalgoldibshop).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(listComsume.ElementAt(z).Value.Count >= index ? Convert.ToInt32(listComsume.ElementAt(z).Value.ElementAt(index - 1).totalgoldspendsilver).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell("0",HorizontalAlign.Center,css)
                               }
                       );
                        z++;
                    }
                    table.Rows.Add(row);
                }

            }
            catch (Exception ex)
            {

            }
            return table;
        }

        private Table get_ChangeServer(List<DateTime> dateTimeList)
        {
            Table table = new Table();
            table.CssClass = "table1";
            TableRow rowHeader = new TableRow();
            TableRow rowTitle = new TableRow();
            rowTitle.Cells.AddRange
            (
                new TableCell[]
                {
                    UIHelpers.CreateTableCell("Tổng cộng các Server", HorizontalAlign.Center,"cell1",7),
                }
            );
            rowHeader.Cells.AddRange(
                new TableCell[]
                { 
                    UIHelpers.CreateTableCell("Ngày",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng đổi",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu đổi Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu hao trong IB Shop",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tiêu hao thị trường đấu giá Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tiêu hao khác",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                }
            );
            table.Rows.Add(rowHeader);

            Dictionary<string, List<OriginGoldShopData>> dataGoldChangePoint = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getChangePointGoldshop(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldSpend = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getTotalGoldSpend(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldSpendSilver = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getTotalGoldSpendSilver(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldChangeSilver = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getTotalGoldChangeSilver(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldIBShop = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getTotalGoldIBShop(dateTimeList);

            try
            {
                string css;
                int stt = 0;



                foreach (var item in dataGoldSpend)
                {


                    rowTitle.Cells.AddRange
                    (
                        new TableCell[]
                        {
                            UIHelpers.CreateTableCell(item.Key,Unit.Percentage(5), HorizontalAlign.Center,"cell1",7),
                        }
                    );
                    if ((stt + 1) == dataGoldSpend.Count())
                    {
                        table.Rows.Add(rowTitle);
                    }

                    rowHeader.Cells.AddRange(
                       new TableCell[]
                        { 
                            UIHelpers.CreateTableCell("Ngày",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng đổi",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu đổi Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu hao trong IB Shop",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tiêu hao thị trường đấu giá Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tiêu hao khác",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                        }
                   );
                    if ((stt + 1) == dataGoldSpend.Count())
                    {
                        table.Rows.Add(rowHeader);
                    }
                    stt++;
                }
                    int index = 0;

                    foreach (var record in dataGoldSpend.ElementAt(0).Value)
                    {

                        int totalGoldChangePoint = 0;
                        int totalGoldSpend = 0;
                        int totalGoldSpendSilver = 0;
                        int totalGoldChangeSilver = 0;
                        int totalGoldIBShop = 0;


                        index++;
                        css = index % 2 == 0 ? "cell1" : "cell2";
                        TableRow row = new TableRow();



                        int j = 0;
                        while (j < dataGoldSpend.Count)
                        {

                            totalGoldChangePoint += dataGoldChangePoint.Count != 0 && dataGoldChangePoint.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldChangePoint.ElementAt(j).Value.ElementAt(index - 1).TotalGoldPoint) : 0;
                            totalGoldSpend += dataGoldSpend.Count != 0 && dataGoldSpend.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldSpend.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            totalGoldSpendSilver += dataGoldSpendSilver.Count != 0 && dataGoldSpendSilver.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldSpendSilver.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            totalGoldChangeSilver += dataGoldChangeSilver.Count != 0 && dataGoldChangeSilver.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldChangeSilver.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            totalGoldIBShop += dataGoldIBShop.Count != 0 && dataGoldIBShop.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldIBShop.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            j++;
                        }



                      
                            row.Cells.AddRange
                            (
                                new TableCell[]
                               {
                                    UIHelpers.CreateTableCell(record.DateTime.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldChangePoint).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldSpend).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),    
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldChangeSilver).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldIBShop).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Convert.ToInt32(totalGoldSpendSilver).ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell("0",HorizontalAlign.Center,css)
                               }
                            );
                       
                        int z = 0;
                        while (z < dataGoldSpend.Count)
                        {
                            row.Cells.AddRange
                           (
                               new TableCell[]
                               {
                                    UIHelpers.CreateTableCell(record.DateTime.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(dataGoldChangePoint.Count!=0 && dataGoldChangePoint.ElementAt(z).Value.Count != 0 ? (Convert.ToInt32(dataGoldChangePoint.ElementAt(z).Value.ElementAt(index - 1).TotalGoldPoint)).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(dataGoldSpend.Count!=0 && dataGoldSpend.ElementAt(z).Value.Count != 0 ? (Convert.ToInt32(dataGoldSpend.ElementAt(z).Value.ElementAt(index - 1).TotalGoldSpend)).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),    
                                    UIHelpers.CreateTableCell(dataGoldChangeSilver.Count != 0 && dataGoldChangeSilver.ElementAt(z).Value.Count != 0 ? Convert.ToInt32(dataGoldChangeSilver.ElementAt(z).Value.ElementAt(index - 1).TotalGoldSpend).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(dataGoldIBShop.Count != 0 && dataGoldIBShop.ElementAt(z).Value.Count != 0 ? Convert.ToInt32(dataGoldIBShop.ElementAt(z).Value.ElementAt(index - 1).TotalGoldSpend).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(dataGoldSpendSilver.Count != 0 && dataGoldSpendSilver.ElementAt(z).Value.Count != 0 ? Convert.ToInt32(dataGoldSpendSilver.ElementAt(z).Value.ElementAt(index - 1).TotalGoldSpend).ToString("N0", CultureInfo.InvariantCulture) : "0",HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell("0",HorizontalAlign.Center,css)
                               }
                           );
                            z++;
                        }                       
                        table.Rows.Add(row);
                    }
                   

                

            }
            catch (Exception ex)
            {

            }
            return table;
        }


        private Table _get_ChangeServer(List<DateTime> dateTimeList)
        {
            Table table = new Table();
            table.CssClass = "table1";
            TableRow rowHeader = new TableRow();
            TableRow rowTitle = new TableRow();
            rowTitle.Cells.AddRange
            (
                new TableCell[]
                {
                    UIHelpers.CreateTableCell("Tổng cộng các Server", HorizontalAlign.Center,"cell1",7),
                }
            );
            rowHeader.Cells.AddRange(
                new TableCell[]
                { 
                    UIHelpers.CreateTableCell("Ngày",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng đổi",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu đổi Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tổng Vàng tiêu hao trong IB Shop",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tiêu hao thị trường đấu giá Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Tiêu hao khác",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                }
            );
            table.Rows.Add(rowHeader);

            Dictionary<string, List<OriginGoldShopData>> dataGoldChangePoint = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getChangePointGoldshop(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldSpend = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getTotalGoldSpend(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldSpendSilver = new Dictionary<string, List<OriginGoldShopData>>(); //.getTotalGoldSpendSilver(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldChangeSilver = new Dictionary<string, List<OriginGoldShopData>>(); //WebDB_N.getTotalGoldChangeSilver(dateTimeList);
            Dictionary<string, List<OriginGoldShopData>> dataGoldIBShop = new Dictionary<string, List<OriginGoldShopData>>(); // WebDB_N.getTotalGoldIBShop(dateTimeList);

            try
            {
                string css;
                int stt = 0;



                foreach (var item in dataGoldSpend)
                {


                    rowTitle.Cells.AddRange
                    (
                        new TableCell[]
                        {
                            UIHelpers.CreateTableCell(item.Key,Unit.Percentage(5), HorizontalAlign.Center,"cell1",7),
                        }
                    );
                    if ((stt + 1) == dataGoldSpend.Count())
                    {
                        table.Rows.Add(rowTitle);
                    }


                    rowHeader.Cells.AddRange(
                       new TableCell[]
                        { 
                            UIHelpers.CreateTableCell("Ngày",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng đổi",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu đổi Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tổng Vàng tiêu hao trong IB Shop",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tiêu hao thị trường đấu giá Bạc",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                            UIHelpers.CreateTableCell("Tiêu hao khác",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                        }
                   );
                    if ((stt + 1) == dataGoldSpend.Count())
                    {
                        table.Rows.Add(rowHeader);
                    }

                    int index = 0;

                    foreach (var record in item.Value)
                    {

                        int totalGoldChangePoint = 0;
                        int totalGoldSpend = 0;
                        int totalGoldSpendSilver = 0;
                        int totalGoldChangeSilver = 0;
                        int totalGoldIBShop = 0;


                        index++;
                        css = index % 2 == 0 ? "cell1" : "cell2";
                        TableRow row = new TableRow();



                        int j = 0;
                        while (j < dataGoldSpend.Count)
                        {

                            totalGoldChangePoint += dataGoldChangePoint.Count != 0 && dataGoldChangePoint.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldChangePoint.ElementAt(j).Value.ElementAt(index - 1).TotalGoldPoint) : 0;
                            totalGoldSpend += dataGoldSpend.Count != 0 && dataGoldSpend.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldSpend.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            totalGoldSpendSilver += dataGoldSpendSilver.Count != 0 && dataGoldSpendSilver.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldSpendSilver.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            totalGoldChangeSilver += dataGoldChangeSilver.Count != 0 && dataGoldChangeSilver.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldChangeSilver.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            totalGoldIBShop += dataGoldIBShop.Count != 0 && dataGoldIBShop.ElementAt(j).Value.Count != 0 ? Convert.ToInt32(dataGoldIBShop.ElementAt(j).Value.ElementAt(index - 1).TotalGoldSpend) : 0;
                            j++;
                        }

                        if ((stt + 1) == dataGoldSpend.Count())
                        {
                            row.Cells.AddRange
                            (
                                new TableCell[]
                               {
                                    UIHelpers.CreateTableCell(record.DateTime.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(totalGoldChangePoint.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(totalGoldSpend.ToString(),HorizontalAlign.Center,css),    
                                    UIHelpers.CreateTableCell(totalGoldChangeSilver.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(totalGoldIBShop.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(totalGoldSpendSilver.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell("0",HorizontalAlign.Center,css)
                               }
                            );
                        }

                        row.Cells.AddRange
                        (
                            new TableCell[]
                           {
                                UIHelpers.CreateTableCell(record.DateTime.ToString(),HorizontalAlign.Center,css),
                                UIHelpers.CreateTableCell(dataGoldChangePoint.Count!=0 && dataGoldChangePoint.ElementAt(stt).Value.Count != 0 ? String.Format(CultureInfo.InvariantCulture,"{0:0,0}", dataGoldChangePoint.ElementAt(stt).Value.ElementAt(index - 1).TotalGoldPoint) : "0",HorizontalAlign.Center,css),
                                UIHelpers.CreateTableCell(record.TotalGoldSpend,HorizontalAlign.Center,css),    
                                UIHelpers.CreateTableCell(dataGoldChangeSilver.Count != 0 && dataGoldChangeSilver.ElementAt(stt).Value.Count != 0 ? dataGoldChangeSilver.ElementAt(stt).Value.ElementAt(index - 1).TotalGoldSpend : "0",HorizontalAlign.Center,css),
                                UIHelpers.CreateTableCell(dataGoldIBShop.Count != 0 && dataGoldIBShop.ElementAt(stt).Value.Count != 0 ? dataGoldIBShop.ElementAt(stt).Value.ElementAt(index - 1).TotalGoldSpend : "0",HorizontalAlign.Center,css),
                                UIHelpers.CreateTableCell(dataGoldSpendSilver.Count != 0 && dataGoldSpendSilver.ElementAt(stt).Value.Count != 0 ? dataGoldSpendSilver.ElementAt(stt).Value.ElementAt(index - 1).TotalGoldSpend : "0",HorizontalAlign.Center,css),
                                UIHelpers.CreateTableCell("0",HorizontalAlign.Center,css)
                           }
                        );
                        table.Rows.Add(row);


                    }
                    stt++;

                }

            }
            catch (Exception ex)
            {

            }
            return table;
        }

        private object Sum()
        {
            throw new NotImplementedException();
        }

    }
}